<!-- 

Displays the different tables depending on parameters and ResultSet from OwnerDb.

-->
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="com.hungryinlindholmen.OwnerDb" import="java.sql.ResultSet"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<link rel="stylesheet" type="text/css" href="Style.css"/>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
	<title>Hungry In Lindholmen - Find where you can eat what you want to eat</title>

<!-- 

Initialize variables which will be used later on the page. 

-->

		<%
			OwnerDb result = (OwnerDb) request.getAttribute("OwnerDb");
			int table = result.getTable();
			int option = result.getOption();
		%>
		
	<SCRIPT TYPE="text/javascript">

function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width=1610,height=730,scrollbars=yes,left=100,top=100,toolbar=yes,rezisable=yes');
return false;

</SCRIPT>	
	
	
</head>
<body>

<div id="container">

	<!-- Header div has link to logout. -->
	
	<div id="header">
		<img src="header3.png">
		<div id="owner">
			<a id="owner" href="Logout">Logout</a>
		</div>
	</div>

	<form class="form-wrapper" method="post" action="OwnerServlet">
		<input type="radio" name="radioButton" value="a" checked>
		<b>a La Carte Menu</b>
		<input type="radio" name="radioButton" value="b" >
		<b>User/Pass</b>
		<input type="radio" name="radioButton" value="c" >
		<b>Lunch Menu</b>
		<input type="radio" name="radioButton" value="d" >
		<b>Restaurant Info</b>
		<input type="radio" name="radioButton" value="e" >
		<b>Opening Hours</b>
		<INPUT TYPE="submit" VALUE="Show table"> 
		
	</form>
	
	<div id="restaurantlist">
		<b>Statistics</b>
		<ul>
			<li><A HREF="ChartServlet?type=a&restId=<%=request.getSession().getAttribute("restID") %>" onClick="return popup(this, 'notes')">Top 10 Dishes</A>
			<li><A HREF="ChartServlet?type=b&restId=<%=request.getSession().getAttribute("restID") %>" onClick="return popup(this, 'notes')">Top 10 Searches</A>
			<li><A HREF="ChartServlet?type=c&restId=<%=request.getSession().getAttribute("restID") %>" onClick="return popup(this, 'chart')">Top 10 Restaurants</A>		
			<li><A HREF="ChartServlet?type=d&restId=<%=request.getSession().getAttribute("restID") %>" onClick="return popup(this, 'chart')">Top 10 Lunch Dishes</A>
		</ul>
	</div>
	
	
	<div id="searchresultpage">
<!-- 

	Displays all the requested data from OwnerDb in tables.
	Form "frm" to get input from text fields to send to NewServlet in order to add new row.
	Links used to send data to edit.jsp and DeleteServlet. 
	Different tables will have different options of edit/new/delete. 
	
-->
	<form name="frm" method="get" action="NewServlet">
		
		<table>
	<%
	
	if(result != null && table == 1){ 
		ResultSet rs = result.getResultSet();
		String altClass = "even";
		int i=0;
	%>
	
	
		<tr>
			<th><%= rs.getMetaData().getColumnName(1)%></th>
			<th><%= rs.getMetaData().getColumnName(2)%></th>
			<th><%= rs.getMetaData().getColumnName(3)%></th>
			<th><%= rs.getMetaData().getColumnName(4)%></th>			
			<th></th>	
			<th></th>
		</tr>
		
		<tr>
			<td><input type="text" name="dishAla"></td>
			<td><input type="text" name="descriptionAla"></td>
			<td><input type="text" name="priceAla" size="3"></td>
			<td><input type="text" name="typeAla" size="6"></td>			
			<td><input type="submit" name="submit" value="NEW"></td>	
			<td></td>
		</tr>
		
		<%while(rs.next()){ %>
			<tr class="<%=altClass %>">
			
				<td><%=rs.getString(1) %></td>
				<td><%=rs.getString(2) %></td>
				<td><%=rs.getString(3) %></td>				
				<td><%=rs.getString(4) %></td>
				<td><A HREF="edit.jsp?input_1=<%= rs.getString(1) %>&input_2=
				<%= rs.getString(2) %>&input_3=<%= rs.getString(3) %>&input_4=<%= rs.getString(4) %>&option=<%= option %>">Edit</A></td>
				<td><A HREF="DeleteServlet?dish=<%= rs.getString(1) %>&option=<%= option %>" 
				onclick="return confirm('Are you sure you want to delete <%= rs.getString(1) %>?')">Delete</A></td>
				<%
				if(altClass.equals("even"))
					altClass = "odd";
				else
					altClass = "even";
				
				%>
			</tr>
			<%} %>
		
		<%} %>
		
<%
	
	if(result != null && table == 2){ 
		ResultSet rs = result.getResultSet();
		String altClass = "even";
		int i=0;
	%>

		<tr>
			<th><%= rs.getMetaData().getColumnName(1)%></th>
			<th><%= rs.getMetaData().getColumnName(2)%></th>
			<th><%= rs.getMetaData().getColumnName(3)%></th>
			<th></th>			
			
	
		<%while(rs.next()){ %>
			<tr class="<%=altClass %>">
			
				<td><%=rs.getString(1) %></td>
				<td><%=rs.getString(2) %></td>
				<td><%=rs.getString(3) %></td>				
				
				<td><A HREF="edit.jsp?input_1=<%= rs.getString(1) %>&input_2=
				<%= rs.getString(2) %>&input_3=<%= rs.getString(3) %>&option=<%= option %>">Edit</A></td>
				<%
				if(altClass.equals("even"))
					altClass = "odd";
				else
					altClass = "even";
				
				%>
			</tr>
			<%} %>
		
		<%} %>		
		
		<%
	
	if(result != null && table == 3){ 
		ResultSet rs = result.getResultSet();
		String altClass = "even";
		int i=0;
	%>
	
	
		<tr>
			<th><%= rs.getMetaData().getColumnName(1)%></th>
			<th><%= rs.getMetaData().getColumnName(2)%></th>
			<th><%= rs.getMetaData().getColumnName(3)%></th>
			<th><%= rs.getMetaData().getColumnName(4)%></th>	
			<th><%= rs.getMetaData().getColumnName(5)%></th>		
			<th></th>
			<th></th>	
			
		</tr>
		
		<tr>
			<td><input type="text" name="dateLunch" size="6"></td>
			<td><input type="text" name="dishLunch" size="11"></td>
			<td><input type="text" name="DescriptionLunch"></td>
			<td><input type="text" name="priceLunch" size="3"></td>			
			<td><input type="text" name="typeLunch" size="6"></td>	
			<td><input type="submit" name="submit" value="NEW"></td>
		</tr>
		
		<%while(rs.next()){ %>
			<tr class="<%=altClass %>">
			
				<td><%=rs.getString(1) %></td>
				<td><%=rs.getString(2) %></td>
				<td><%=rs.getString(3) %></td>				
				<td><%=rs.getString(4) %></td>
				<td><%=rs.getString(5) %></td>
				<td><A HREF="edit.jsp?input_1=<%= rs.getString(1) %>&input_2=<%= rs.getString(2) %>&input_3=
				<%= rs.getString(3) %>&input_4=<%= rs.getString(4) %>&input_5=<%= rs.getString(5) %>&option=<%= option %>">Edit</A></td>
				<td><A HREF="DeleteServlet?dish=<%= rs.getString(2) %>&option=<%= option %>"
				onclick="return confirm('Are you sure you want to delete <%= rs.getString(2) %>?')">Delete</A></td>
				<%
				if(altClass.equals("even"))
					altClass = "odd";
				else
					altClass = "even";
				
				%>
			</tr>
			<%} %>
		
		<%} %>
		
		<%
	
	if(result != null && table == 4){ 
		ResultSet rs = result.getResultSet();
		String altClass = "even";
		int i=0;
	%>
	
		<tr>
			<th><%= rs.getMetaData().getColumnName(1)%></th>
			<th><%= rs.getMetaData().getColumnName(2)%></th>
			<th><%= rs.getMetaData().getColumnName(3)%></th>
			<th><%= rs.getMetaData().getColumnName(4)%></th>
			<th></th>			
				
			
		</tr>
		<%while(rs.next()){ %>
			<tr class="<%=altClass %>">
			
				<td><%=rs.getString(1) %></td>
				<td><%=rs.getString(2) %></td>
				<td><%=rs.getString(3) %></td>
				<td><%=rs.getString(4) %></td>				
				<td><A HREF="edit.jsp?input_1=<%= rs.getString(1) %>&input_2=
				<%= rs.getString(2) %>&input_3=<%= rs.getString(3) %>&option=<%= option %>">Edit</A></td>
				<%
				if(altClass.equals("even"))
					altClass = "odd";
				else
					altClass = "even";
				
				%>
			</tr>
			<%} %>
		
		<%} %>
		
		<%
	
	if(result != null && table == 5){ 
		ResultSet rs = result.getResultSet();
		String altClass = "even";
		int i=0;
	%>
	
	
		<tr>
			<th><%= rs.getMetaData().getColumnName(1)%></th>
			<th><%= rs.getMetaData().getColumnName(2)%></th>
			<th><%= rs.getMetaData().getColumnName(3)%></th>
			<th><%= rs.getMetaData().getColumnName(4)%></th>	
			<th><%= rs.getMetaData().getColumnName(5)%></th>
			<th><%= rs.getMetaData().getColumnName(6)%></th>
			<th><%= rs.getMetaData().getColumnName(7)%></th>		
			<th></th>
			
			
		</tr>
		<%while(rs.next()){ %>
			<tr class="<%=altClass %>">
			
				<td><%=rs.getString(1) %></td>
				<td><%=rs.getString(2) %></td>
				<td><%=rs.getString(3) %></td>				
				<td><%=rs.getString(4) %></td>
				<td><%=rs.getString(5) %></td>
				<td><%=rs.getString(6) %></td>
				<td><%=rs.getString(7) %></td>
				
				<td><A HREF="edit.jsp?input_1=<%= rs.getString(1) %>&input_2=
				<%= rs.getString(2) %>&input_3=<%= rs.getString(3) %>&input_4=<%= rs.getString(4) %>
				&input_5=<%= rs.getString(5) %>&input_6=<%= rs.getString(7) %>&input_7=<%= rs.getString(7) %>&option=<%= option %>">Edit</A></td>
				
				<%
				if(altClass.equals("even"))
					altClass = "odd";
				else
					altClass = "even";
				
				%>
			</tr>
			<%} %>
		
		<%} %>
		
	</table>
	</form>
	</div>
	

	<!-- The page's footer -->

	<div id="footer">
		Hungry In Lindholmen created by Group 6 Saturn<br>
		For more information, questions or whatever send us an 
		<a href="mailto:olof.ekelund84@gmail.com?subject=HungryInLindholmen"> e-mail.</a>
	</div>
	
</div>
</body>
</html>